package mutsumimod.patches;

import basemod.ReflectionHacks;
import com.evacipated.cardcrawl.modthespire.lib.*;
import com.megacrit.cardcrawl.actions.AbstractGameAction;
import com.megacrit.cardcrawl.actions.common.ApplyPowerAction;
import com.megacrit.cardcrawl.core.AbstractCreature;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.powers.AbstractPower;
import mutsumimod.powers.SkyBallDebuffPower;
import mutsumimod.powers.SkyBallPower;

public class SkyBallPatch {


    @SpirePatch(
            clz = ApplyPowerAction.class,
            method = SpirePatch.CONSTRUCTOR,
            paramtypez = {
                AbstractCreature.class, AbstractCreature.class, AbstractPower.class, int.class, boolean.class, AbstractGameAction.AttackEffect.class
            }
    )
    public static class ApplyPowerActionPatch {
        @SpirePostfixPatch
        public static void postfix(ApplyPowerAction __instance,AbstractCreature target, AbstractCreature source, AbstractPower powerToApply, int stackAmount, boolean isFast, AbstractGameAction.AttackEffect effect){
            AbstractPower power=ReflectionHacks.getPrivate(__instance, ApplyPowerAction.class,"powerToApply");
            if(AbstractDungeon.player.hasPower(SkyBallPower.POWER_ID)&&power.type.equals(AbstractPower.PowerType.DEBUFF)&&target.equals(AbstractDungeon.player)){
                ReflectionHacks.setPrivate(__instance,ApplyPowerAction.class,"powerToApply",
                        new SkyBallDebuffPower(power));
            }
        }

    }
}
